package org.geektimes.projects.user.web.controller;

import org.geektimes.injection.annotation.RequestBody;
import org.geektimes.injection.annotation.ResponseJson;
import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.service.UserService;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.List;

/**
 * @FileName: UserRegisterCongtroller
 * @Description: 用户注册controller
 * @Author: MaWenHao
 * @Created: 2021/3/2 - 上午12:20
 */
@Path("/user")
public class UserRegisterController {

    @Resource(name = "UserServiceImpl")
    private UserService userService;

    @POST
    @Path("/add")
    public String registerUser(@RequestBody User user) {
        boolean register = userService.register(user);
        if (register) {
            return "redirect:index.jsp";
        }
        return "redirect:register.jsp";
    }

    @GET
    @ResponseJson
    public List<User> getAll() {
        List<User> users = userService.getALL();
        return users;
    }
}
